package yo.latyoo.hokage.skmr.biz.repository;

import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import yo.latyoo.hokage.skmr.biz.domain.JobLog;

import java.time.LocalDateTime;
import java.util.List;

public interface JobLogRepo extends JpaSpecificationExecutor<JobLog>, JpaRepository<JobLog, Long> {

    List<JobLog> findByTriggerCodeAndResultCodeAndTriggerTimeLessThanEqual(int triggerCode, int resultCode, LocalDateTime triggerTime);

    @Transactional
    @Modifying
    @Query("update JobLog set triggerCode = ?1,triggerMsg = ?2,triggerTime = ?3 where id = ?4")
    void updateTrigger(int triggerCode, String triggerMsg, LocalDateTime triggerTime, Long id);

    @Transactional
    @Modifying
    @Query("update JobLog set resultCode = ?1,resultMsg = ?2,resultTime = ?3 where id = ?4")
    void updateResult(int resultCode, String resultMsg, LocalDateTime resultTime, Long id);
}
